package com.ytjj.bigdata.service;

import com.github.pagehelper.PageHelper;
import com.ytjj.bigdata.dao.AdsAppContentMapper;
import com.ytjj.bigdata.entity.*;
import com.ytjj.bigdata.model.dto.*;
import com.ytjj.common.api.CommonPageExtend;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class AdsAppContentService {

    @Resource
    private AdsAppContentMapper adsAppContentMapper;

    public CommonPageExtend selectAdsAppContent(AdsAppContentDto adsAppContentDto) {
        PageHelper.startPage(adsAppContentDto.getPageNum(),adsAppContentDto.getPageSize());
        List<AdsAppContent> list = adsAppContentMapper.selectAdsAppCountentAll(adsAppContentDto);

        if (CollectionUtils.isEmpty(list)) {
            return new CommonPageExtend();
        }

        CommonPageExtend<AdsAppContent> pageExtend = CommonPageExtend.restPage(list);

        return pageExtend;
    }

    public CommonPageExtend selectAdsHomePageAll(AdsHomePageDto adsHomePageDto) {
        PageHelper.startPage(adsHomePageDto.getPageNum(),adsHomePageDto.getPageSize());
        List<AdsHomePage> list = adsAppContentMapper.selectAdsHomePageAll(adsHomePageDto);

        if (CollectionUtils.isEmpty(list)) {
            return new CommonPageExtend();
        }

        CommonPageExtend<AdsHomePage> pageExtend = CommonPageExtend.restPage(list);

        return pageExtend;
    }

    public CommonPageExtend selectAdsEvaluateDetailAll(AdsEvaluateDetailDto adsEvaluateDetailDto) {
        PageHelper.startPage(adsEvaluateDetailDto.getPageNum(),adsEvaluateDetailDto.getPageSize());
        List<AdsEvaluateDetail> list = adsAppContentMapper.selectAdsEvaluateDetailAll(adsEvaluateDetailDto);

        if (CollectionUtils.isEmpty(list)) {
            return new CommonPageExtend();
        }

        CommonPageExtend<AdsEvaluateDetail> pageExtend = CommonPageExtend.restPage(list);

        return pageExtend;
    }

    public CommonPageExtend selectAdsAppContentSummaryAll(AdsAppContentSummaryDto adsAppContentSummaryDto) {
        PageHelper.startPage(adsAppContentSummaryDto.getPageNum(), adsAppContentSummaryDto.getPageSize());
        List<AdsAppContentSummary> list = adsAppContentMapper.selectAdsAppContentSummaryAll(adsAppContentSummaryDto);

        if (!CollectionUtils.isEmpty(list)) {
            list.stream().map(item -> {
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                item.setDate(format.format(item.getUpDt()));
                return item;
            }).collect(Collectors.toList());
            return CommonPageExtend.restPage(list);
        }

        return new CommonPageExtend();
    }

    public CommonPageExtend selectAdsAppPostAll(AdsAppPostDto adsAppPostDto) {
        PageHelper.startPage(adsAppPostDto.getPageNum(),adsAppPostDto.getPageSize());
        List<AdsAppPost> list = adsAppContentMapper.selectAdsAppPostAll(adsAppPostDto);

        if (CollectionUtils.isEmpty(list)) {
            return new CommonPageExtend();
        }

        return CommonPageExtend.restPage(list);
    }

    public CommonPageExtend selectAdsAppRetentionAll(AdsAppRetentionDto adsAppRetentionDto) {
        PageHelper.startPage(adsAppRetentionDto.getPageNum(),adsAppRetentionDto.getPageSize());
        List<AdsAppRetention> list = adsAppContentMapper.selectAdsAppRetentionAll(adsAppRetentionDto);

        if (CollectionUtils.isEmpty(list)) {
            return new CommonPageExtend();
        }

        return CommonPageExtend.restPage(list);
    }

    public CommonPageExtend selectAdsAppBehaviorAll(AdsAppBehaviorDto adsAppBehaviorDto) {
        PageHelper.startPage(adsAppBehaviorDto.getPageNum(),adsAppBehaviorDto.getPageSize());
        List<AdsAppBehavior> list = adsAppContentMapper.selectAdsAppBehaviorAll(adsAppBehaviorDto);

        if (CollectionUtils.isEmpty(list)) {
            return new CommonPageExtend();
        }

        return CommonPageExtend.restPage(list);
    }

    public CommonPageExtend selectEvaluateDetailWeek(AdsEvaluateDetailWeekDto adsEvaluateDetailWeekDto) {
        PageHelper.startPage(adsEvaluateDetailWeekDto.getPageNum(),adsEvaluateDetailWeekDto.getPageSize());
        List<AdsEvaluateDetailWeek> list = adsAppContentMapper.selectEvaluateDetailWeek(adsEvaluateDetailWeekDto);

        if (CollectionUtils.isEmpty(list)) {
            return new CommonPageExtend();
        }

        return CommonPageExtend.restPage(list);
    }
}
